package main.java.study.datastructure.queue;

/**
 * <p>队列模拟</p>
 *
 * @author LiShaoWen
 * @date 2021/10/12 21:51
 */
public class ArrayQueueDemo {

    public static void main(String[] args) {
        int i = 2%5;
        System.out.println(2%5);
    }

}








class ArrayQueue{
    private int[] array;
    private int rear;
    private int front;
    private int maxSize;

    public ArrayQueue(int arrayMaxSize){
        maxSize = arrayMaxSize;
        array = new int[arrayMaxSize];
        // 指向队列头的前一个位置，不包含数据
        front = -1;
        // 指向对列尾的数据
        rear = -1;
    }

    public boolean isFull(){
        return rear == maxSize-1;
    }

    public boolean isEmpty(){
        return rear == front;
    }

    public void add(int n){
        if (isFull()){
            System.out.println("对列已满");
            return;
        }
        array[++rear] = n;
    }

    public int get(){
        if (isEmpty()){
            throw new RuntimeException("对列空");
        }
        return array[++front];
    }

    public int head(){
        if (isEmpty()){
            throw new RuntimeException("对列空");
        }
        return array[front+1];
    }

}